#include <bits/stdc++.h>
using namespace std;
int T;
int a[200005];
long long maxa = 0;
int n;
void dfs(int x, int y, long long sum, int dp) {
    if(dp == n) {
        maxa = max(maxa, sum);
        return;
    }
    dfs(a[dp + 1], y, (x == a[dp + 1]) * a[dp + 1] + sum, dp + 1);
    dfs(x, a[dp + 1], (y == a[dp + 1]) * a[dp + 1] + sum, dp + 1);
}
int main() {
    freopen("color.in", "r", stdin);
    freopen("color.out", "w", stdout);
    cin >> T;
    while(T--) {
        cin >> n;
        memset(a, 0, sizeof(a));
        maxa = 0;
        for(int i = 1; i <= n; i++) {
            cin >> a[i];
        }
        dfs(-1, -1, 0, 0);
        cout << maxa << endl;
    }
    return 0;
}
